﻿// ------------------------------------------------------------------------------------------------
// <copyright file="ZipHelper.cs" company="Hiyoko">
//   Copyright (c) 2015 All Rights Reserved
// </copyright>
// <summary>
//   This helper class provide methods for zipping and unzipping files using DotNetZip library.
// </summary>
// ---------------------------------------------------------------------------------------------

using System;
using System.IO;
using System.IO.Compression;
using System.Reflection;

namespace Hiyoko.SolutionsComparer.Helper
{
    public static class ZipHelper
    {
        /// <summary>
        /// Unzip specified zip file to disk.
        /// </summary>
        /// <param name="zipFilePath">The zip file path</param>
        /// <param name="destinationPath">The destination folder path</param>
        public static void UnzipToFile(string zipFilePath, string destinationPath)
        {
            if (string.IsNullOrEmpty(zipFilePath))
            {
                throw new ArgumentException(string.Format("The zipFilePath argument is null or empty."));
            }

            if (string.IsNullOrEmpty(destinationPath))
            {
                throw new ArgumentException(string.Format("The destinationPath argument is null or empty."));
            }

            using (var archive = ZipFile.OpenRead(zipFilePath))
            {
                foreach (var entry in archive.Entries)
                {
                    if (entry.FullName.Equals("customizations.xml", StringComparison.OrdinalIgnoreCase))
                    {
                        entry.ExtractToFile(Path.Combine(destinationPath, entry.FullName));
                    }
                }
            }
        }
    }
}
